<?php

namespace app\admin\model;

use think\Model;

class Order extends Model
{
    public function searchOrderSnAttr($q, $v, $d)
    {
        $q->where('o.order_sn', 'like', "%{$v}%");
    }
    public function searchTimeqAttr($q, $v, $d)
    {
        $q->where('o.addtime', '< TIME', $v);
    }
    public function searchTimehAttr($q, $v, $d)
    {
        $q->where('o.addtime', '> TIME', $v);
    }
    public function searchStatusAttr($q, $v, $d)
    {
        $q->where('o.status', 'in', $v);
    }
    public function searchPrqAttr($q, $v, $d)
    {
        $q->where('o.amount', '>', $v);
    }
    public function searchPrhAttr($q, $v, $d)
    {
        $q->where('o.amount', '<', $v);
    }
    // protected $table = 'table_name';
    // protected $pk = 'id';
    public static function getOrderList($where, $get)
    {
        $list = Order::field('o.id,o.order_sn,o.uid,o.amount,o.addtime,o.status,o.remark,u.uname,s.order_status')
            ->alias('o')
            ->withSearch(array_keys($where), $where)
            ->join('user u', 'o.uid=u.id')
            ->join('order_status s', 'o.status=s.status_id')
            ->paginate([
                'list_rows' => 5,
                'var_page' => 'page',
                'query' => $get,
            ]);
        return $list;
    }
}
